package com.yxw.live_vod_boot.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.yxw.live_vod_boot.entity.YxEmojiEntity;
import com.yxw.live_vod_boot.mapper.EmojiMapper;
import com.yxw.live_vod_boot.service.EmojiService;
import com.yxw.live_vod_boot.vo.EmojiEntityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EmojiServiceImpl implements EmojiService {

    @Autowired
    private EmojiMapper emojiMapper;

    @Override
    public YxEmojiEntity getById(Long emojiId) {
        return emojiMapper.selectById(emojiId);
    }

    @Override
    public List<EmojiEntityVO> getAll() {
        List<YxEmojiEntity> emojiEntities = emojiMapper.selectList(null);
        List<EmojiEntityVO> voList = new ArrayList<>();
        if (emojiEntities != null && !emojiEntities.isEmpty()) {
            voList = BeanUtil.copyToList(emojiEntities, EmojiEntityVO.class);
        }
        return voList;
    }

    @Override
    public void save(YxEmojiEntity emoji) {
        emojiMapper.insert(emoji);
    }

    @Override
    public void update(YxEmojiEntity emoji) {
        emojiMapper.updateById(emoji);
    }

    @Override
    public void deleteById(Long emojiId) {
        emojiMapper.deleteById(emojiId);
    }
}